import { Button, Form, Input } from 'antd-mobile'
import React from 'react'
import utils from '../../utils/utils'
import { useNavigate } from 'react-router-dom'
const Login = () => {
    const navigate = useNavigate()
    const onFinish = async (values) => {
        console.log(values);
        const resp=await utils.post('/login',values)
        const { data, code, message } = resp.data;
        if (code === 200) {
            localStorage.setItem('token', data.token)
            alert(message)
            navigate("/")
        } else {
            alert(message)
        }
    }
    return (
        <div>
            登录
            <Form
                onFinish={onFinish}
                footer={
                    <Button block type='submit' color='primary'>
                        登录
                    </Button>
                }
            >
                <Form.Item name='username' label='账号'>
                    <Input></Input>
                </Form.Item>
                <Form.Item name='password' label='密码'>
                    <Input></Input>
                </Form.Item>
            </Form>
        </div>
    )
}

export default Login
